package com.doordu.soa.service.data.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.doordu.soa.service.comm.ResultCode;
import com.doordu.soa.service.data.service.LogSyncService;
import com.doordu.soa.service.data.vo.LogSyncErrorVo;
import com.doordu.soa.service.data.vo.LogSyncResultVo;
import com.doordu.soa.service.data.vo.QuerySyncLogErrorVo;
import com.doordu.soa.service.data.vo.QuerySyncLogVo;
import com.doordu.soa.service.web.annotation.NotLogin;
import com.doordu.soa.service.web.annotation.Ver;
import com.doordu.soa.service.web.utils.BaseController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

@Api(tags = "LogSync", description = "同步日志查询信息接口")
@RestController
@RequestMapping("/parking/log")
public class LogSyncController extends BaseController {

	private final Logger logger = LoggerFactory.getLogger(LogSyncController.class);

	@Autowired
	private LogSyncService logSyncService;

	@ApiOperation(value = "同步日志查询", notes = "同步日志查询")
	@ApiResponses({ @ApiResponse(code = 200, message = "处理成功") })
	@ApiImplicitParams({ @ApiImplicitParam(name = "ver", value = "接口版本", paramType = "path", required = true, dataType = "String", defaultValue = "v1") })
	@RequestMapping(path = "/querySyncLog/{ver}", method = { RequestMethod.GET, RequestMethod.POST })
	@Ver("1")
	@NotLogin
	public ResponseEntity<Object> querySyncLog(QuerySyncLogVo query, HttpServletRequest request) {
		query.setCompanyId(getCompanyId(request));
		try{
			List<LogSyncResultVo> result = logSyncService.queryLogSync(query);
			return ok(result, null == result || result.size() == 0 ? 0L : result.size());
		}catch(Exception e){
			logger.error("",e);
			return error(ResultCode.RESPONSE_INTRANET_ERROR,e.getMessage());
		}
	}

	@ApiOperation(value = "上报参数data参数校验-示例", notes = "上报参数data参数校验-示例")
	@ApiResponses({ @ApiResponse(code = 200, message = "处理成功") })
	@ApiImplicitParams({ @ApiImplicitParam(name = "ver", value = "接口版本", paramType = "path", required = true, dataType = "String", defaultValue = "v1")})
			
	@RequestMapping(path = "/querySyncErrorLog/{ver}", method = { RequestMethod.GET, RequestMethod.POST })
	@Ver("1")
	@NotLogin
	public ResponseEntity<Object> queyrSyncErrorLog(QuerySyncLogErrorVo query,HttpServletRequest request) {
		try{
			List<LogSyncErrorVo> result = logSyncService.queryLogSyncError(query.getLogId());
			return ok(result, null == result || result.size() == 0 ? 0L : result.size());
		}catch(Exception e){
			logger.error("",e);
			return error(ResultCode.RESPONSE_INTRANET_ERROR,e.getMessage());
		}
		
	}
}
